package com.ag.common;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.ag.admin.utils.UserSession;
import com.ag.admin.utils.UserUtil;
import com.ag.bean.TbPermission;
import com.ag.bean.TbUser;

/**
 * 权限服务实现类
 * 
 * @author 黎肇明
 * 
 */
@Service("PermissionServiceImpl")
public class PermissionServiceImpl implements IPermissionService {

	@Override
	public boolean checkPermission(Map<String, Object> sessionMap,
			String permission) {
		UserSession userSession = (UserSession) sessionMap
				.get(UserUtil.USER_SESSION);
		Map<String, Map<String, TbPermission>> pmsnMap = userSession
				.getUserPemission();
		for (String roleStr : pmsnMap.keySet()) {
			Map<String, TbPermission> pMap = pmsnMap.get(roleStr);
			if (pMap.containsKey(permission)) {
				return true;
			}
		}
		return false;
	}

	@Override
	public TbUser getCurrentUser(Map<String, Object> sessionMap) {
		UserSession userSession = (UserSession) sessionMap
				.get(UserUtil.USER_SESSION);
		return userSession.getTbUser();
	}

	static TbUser getThisUser(Map<String, Object> sessionMap) {
		UserSession userSession = (UserSession) sessionMap
				.get(UserUtil.USER_SESSION);
		return userSession.getTbUser();
	}//在页面判断是否是管理员用的
	
}
